<template>
  <div class="body">
    <div class="counter-warp">
      <view class="forget_pwd">
        <view class="father_accounts marginmini">
          <image class="icon_hide_show" :mode="scaleToFill" src="/static/img/login_icon_eyeope.png" v-show="!showEye" @click="hideShow"></image>
          <image class="icon_hide_close" :mode="scaleToFill" src="/static/img/login_icon_eyeclos.png" v-show="showEye" @click="hideShow"></image>
          <input class="accounts" v-if="showEye" maxlength="15" type="password" v-model='regist_password' placeholder="密码"/>
          <input class="accounts" v-else type="text" maxlength="15"  v-model='regist_password' placeholder="密码"/>
          <image class="acc_icon" :mode="scaleToFill" src="/static/img/ic_password.png"></image>
        </view>
        <view :class="canNext? 'btnCanNext' : 'btnNext'"  @click="toFinish">完成</view>
        <view>
        </view>
      </view>
    </div>
  </div>
</template>

<script>
// Use Vuex
import api from '@/utils/api'
export default {
  data () {
    return {
      canNext: false,
      canSend: false,
      regist_password: '',
      regist_account: '',
      showEye: true
    }
  },
  watch: {
    regist_password (curVal, oldVal) {
      console.log(curVal, oldVal)
      if (curVal !== '' && curVal.length >= 6) {
        this.canNext = true
      } else {
        this.canNext = false
      }
    }
  },
  methods: {
    toFinish () {
      if (this.canNext) {
        const opforgetpassword = api.opforgetpassword(this.regist_account, this.regist_password, this.regist_password)
        opforgetpassword.then(d => {
          if (d.code === 200) {
            wx.showToast({
              title: '修改成功',
              icon: 'success'
            })
            wx.reLaunch({
              url: '/pages/accounts/login/main'
            })
          }
        })
        .catch((e) => {
          console.log(e)
        })
      }
    },
    hideShow () {
      this.showEye = !this.showEye
    }
  },
  onLoad () {
    this.regist_account = this.$root.$mp.query.cellphone
    console.log(this.regist_account)
  }
}

</script>
<style>
@import './forgetpasswordfinish.css';
</style>
